package com.ofsize.keepmoving.drag;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.ofsize.keepmoving.R;

/**
 * Created by liudengyong on 15/6/5.
 */

public class ImgDragShadowBuilder extends View.DragShadowBuilder {

    private final static int SHADOW_W = 48;
    private final static int SHADOW_H = 48;
    private final static int OFFSET = 10;

    private static Drawable shadow;

    public ImgDragShadowBuilder(View v) {
        super(v);
        shadow = v.getContext().getResources().getDrawable(R.drawable.apple_icon);
    }

    @Override
    public void onProvideShadowMetrics (Point size, Point touch) {
        int width = getView().getWidth();
        int height = getView().getHeight();

        shadow.setBounds(0, 0, SHADOW_W, SHADOW_H);
        size.set(SHADOW_W, SHADOW_H );

        //  拖动阴影以触摸点为中心
        touch.set(SHADOW_W, SHADOW_H + OFFSET);
    }

    @Override
    public void onDrawShadow(Canvas canvas){
        shadow.draw(canvas);
    }
}
